import { request } from '@/utils/axios/axios'
import type { PageNationResult, Brand, CategoryBrandRelation } from '@/api/brand/type'

// 定义与品牌相关的url
enum API {
  // 分页查询品牌信息
  BRAND_LIST = 'brand',
  ADD_BRAND = 'brand/addbrand',
  UPDATE_BRAND = 'brand/updatebrand',
  DELETE_BRAND = 'brand/deletebrand',
  ADD_CATEGORY_TO_BRAND = 'brand/addcategorytobrand',
}
export const brandListRequest = (
  page: number,
  pageSize: number,
  condition: string,
): Promise<PageNationResult> => {
  return request.get<number, PageNationResult>(API.BRAND_LIST + `/${page}/${pageSize}/${condition}`)
}
// 新增品牌的请求
export const addBrandRequest = (data: Brand): Promise<string> => {
  return request.post<Brand, string>(API.ADD_BRAND, data)
}
// 更新品牌的请求
export const updateBrandRequest = (data: Brand): Promise<string> => {
  return request.put<Brand, string>(API.UPDATE_BRAND, data)
}
// 删除品牌信息
export const deleteBrandRequest = (brandIDs: number[]): Promise<string> => {
  return request.delete<number[], string>(API.DELETE_BRAND, { data: brandIDs })
}

// 新增品牌与分类关联关系的请求
export const addCategoryBrandRelation = (
  categoryBrandRelation: CategoryBrandRelation,
): Promise<string> => {
  return request.post<CategoryBrandRelation, string>(
    API.ADD_CATEGORY_TO_BRAND,
    categoryBrandRelation,
  )
}
// 根据品牌id查询关联的分类
export const getCategoryBrandRelationRequest = (
  brandID: number,
): Promise<CategoryBrandRelation[]> => {
  return request.get<number, CategoryBrandRelation>(API.BRAND_LIST + `/${brandID}`)
}
// 删除品牌关联的分类
export const deleteCategoryBrandRelationRequest = (
  categoryBrandRelationID: number,
): Promise<number> => {
  return request.delete<number>(API.BRAND_LIST, {
    params: { categoryBrandRelationID: categoryBrandRelationID },
  })
}
